package com.qdu.mapper;

import com.qdu.bean.WeatherBean2;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class RentPerMonthByWeatherMapper extends Mapper<LongWritable, Text, WeatherBean2, IntWritable> {
    private WeatherBean2 keyout = new WeatherBean2();
    private IntWritable valueout = new IntWritable();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //切分
        String[] items = value.toString().split(",");
        String[] fulltime = items[0].split(" ");
        String[] ymd = fulltime[0].split("/");
        //取出列
        String year = ymd[0];         //年
        String month = ymd[1];        //月
        int weather = Integer.parseInt(items[4]);      //天气标志
        int count = Integer.parseInt(items[11]);      //所有用车的人数

        //封装对象
        keyout.set(year+'-'+month+' '+weather);
        valueout.set(count);

        context.write(keyout,valueout);
    }
}
